package com.lqq.designPattern.bulider_pattern.singleton.demo4;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Client {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
//        Singleton instance1 = Singleton.getInstance();
//        Singleton instance2 = Singleton.getInstance();
//        //比较是否为同一个对象
//        System.out.println("是否为同一个对象：" + (instance1 == instance2));

        /**
         * 反射破坏单例
         */
        Constructor cons = Singleton.class.getDeclaredConstructor();
        cons.setAccessible(true);
        Singleton instance1 = Singleton.getInstance();
        Singleton instance2 = (Singleton) cons.newInstance();
        //比较是否为同一个对象
        System.out.println("是否为同一个对象：" + (instance1 == instance2));
    }
}
